<template>
  <div>
    <el-page-header content="添加商品" @back="goBack">
    </el-page-header>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="分配账号">
        <el-input v-model="form.a_account"></el-input>
      </el-form-item>
      <el-form-item label="管理员昵称">
        <el-input v-model="form.a_name"></el-input>
      </el-form-item>
      <el-form-item label="管理员密码">
        <el-input v-model="form.a_password"></el-input>
      </el-form-item>
      <!-- a_account, a_name, a_password, a_r_id -->
      <el-form-item label="选择角色">
        <el-select v-model="form.a_r_id" placeholder="选择角色">
          <el-option :label="r.r_nickname" :value="r.r_id" v-for="r in role" :key="r.r_id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data(){
    return {
      date1: '',
      date2: '',
      form: {
        a_account:'',
        a_name:'', 
        a_password:'', 
        a_r_id:''
      },
      // 能源类型
      role:[]
    }
  },
  methods:{
    onSubmit() {
      this.$ajax({
        url:"after/admin",
        method:"post",
        data:this.form
      }).then(resp=>{
        this.$message({
          message: '添加',
          type: 'success'
        });
        this.form.a_account = ''
        this.form.a_name = ''
        this.form.a_password = ''
        this.form.a_r_id = ''
      })
      
      console.log('submit!',this.form);
    },
    goBack() {
      this.$router.push("/")
    },
    init(){
      // 加载角色
      this.$ajax({
        url:"after/role",
        method:"get",
        params:{currentsize:1,pagesize:50}
      }).then(resp=>{
        let energyobj = resp.data.message;
        energyobj.forEach((item,i)=>{
          if(item.r_state==0){
            energyobj.splice(i,1);
          }
        })
        this.role = energyobj
      })
    },
    
    
  },
  created(){
    this.init();
  }
}
</script>

<style scoped>

</style>